<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>mat3f.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_vec_mat3f.js.html">mat3f.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2013 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>
<a name="line16"></a>////////////////////////// NOTE ABOUT EDITING THIS FILE ///////////////////////
<a name="line17"></a>//                                                                           //
<a name="line18"></a>// Any edits to this file must be applied to mat3d.js by running:            //
<a name="line19"></a>//   swap_type.sh mat3f.js &gt; mat3d.js                                        //
<a name="line20"></a>//                                                                           //
<a name="line21"></a>////////////////////////// NOTE ABOUT EDITING THIS FILE ///////////////////////
<a name="line22"></a>
<a name="line23"></a>
<a name="line24"></a>/**
<a name="line25"></a> * @fileoverview Provides functions for operating on 3x3 float (32bit)
<a name="line26"></a> * matrices.  The matrices are stored in column-major order.
<a name="line27"></a> *
<a name="line28"></a> * The last parameter will typically be the output object and an object
<a name="line29"></a> * can be both an input and output parameter to all methods except where
<a name="line30"></a> * noted.
<a name="line31"></a> *
<a name="line32"></a> * See the README for notes about the design and structure of the API
<a name="line33"></a> * (especially related to performance).
<a name="line34"></a> *
<a name="line35"></a> */
<a name="line36"></a>goog.provide(&#39;goog.vec.mat3f&#39;);
<a name="line37"></a>goog.provide(&#39;goog.vec.mat3f.Type&#39;);
<a name="line38"></a>
<a name="line39"></a>goog.require(&#39;goog.vec&#39;);
<a name="line40"></a>
<a name="line41"></a>
<a name="line42"></a>/** @typedef {goog.vec.Float32} */ goog.vec.mat3f.Type;
<a name="line43"></a>
<a name="line44"></a>
<a name="line45"></a>/**
<a name="line46"></a> * Creates a mat3f with all elements initialized to zero.
<a name="line47"></a> *
<a name="line48"></a> * @return {!goog.vec.mat3f.Type} The new mat3f.
<a name="line49"></a> */
<a name="line50"></a>goog.vec.mat3f.create = function() {
<a name="line51"></a>  return new Float32Array(9);
<a name="line52"></a>};
<a name="line53"></a>
<a name="line54"></a>
<a name="line55"></a>/**
<a name="line56"></a> * Initializes the matrix from the set of values. Note the values supplied are
<a name="line57"></a> * in column major order.
<a name="line58"></a> *
<a name="line59"></a> * @param {goog.vec.mat3f.Type} mat The matrix to receive the
<a name="line60"></a> *     values.
<a name="line61"></a> * @param {number} v00 The values at (0, 0).
<a name="line62"></a> * @param {number} v10 The values at (1, 0).
<a name="line63"></a> * @param {number} v20 The values at (2, 0).
<a name="line64"></a> * @param {number} v01 The values at (0, 1).
<a name="line65"></a> * @param {number} v11 The values at (1, 1).
<a name="line66"></a> * @param {number} v21 The values at (2, 1).
<a name="line67"></a> * @param {number} v02 The values at (0, 2).
<a name="line68"></a> * @param {number} v12 The values at (1, 2).
<a name="line69"></a> * @param {number} v22 The values at (2, 2).
<a name="line70"></a> * @return {!goog.vec.mat3f.Type} return mat so that operations can be
<a name="line71"></a> *     chained together.
<a name="line72"></a> */
<a name="line73"></a>goog.vec.mat3f.setFromValues = function(
<a name="line74"></a>    mat, v00, v10, v20, v01, v11, v21, v02, v12, v22) {
<a name="line75"></a>  mat[0] = v00;
<a name="line76"></a>  mat[1] = v10;
<a name="line77"></a>  mat[2] = v20;
<a name="line78"></a>  mat[3] = v01;
<a name="line79"></a>  mat[4] = v11;
<a name="line80"></a>  mat[5] = v21;
<a name="line81"></a>  mat[6] = v02;
<a name="line82"></a>  mat[7] = v12;
<a name="line83"></a>  mat[8] = v22;
<a name="line84"></a>  return mat;
<a name="line85"></a>};
<a name="line86"></a>
<a name="line87"></a>
<a name="line88"></a>/**
<a name="line89"></a> * Initializes mat3f mat from mat3f src.
<a name="line90"></a> *
<a name="line91"></a> * @param {goog.vec.mat3f.Type} mat The destination matrix.
<a name="line92"></a> * @param {goog.vec.mat3f.Type} src The source matrix.
<a name="line93"></a> * @return {!goog.vec.mat3f.Type} Return mat so that operations can be
<a name="line94"></a> *     chained together.
<a name="line95"></a> */
<a name="line96"></a>goog.vec.mat3f.setFromMat3f = function(mat, src) {
<a name="line97"></a>  mat[0] = src[0];
<a name="line98"></a>  mat[1] = src[1];
<a name="line99"></a>  mat[2] = src[2];
<a name="line100"></a>  mat[3] = src[3];
<a name="line101"></a>  mat[4] = src[4];
<a name="line102"></a>  mat[5] = src[5];
<a name="line103"></a>  mat[6] = src[6];
<a name="line104"></a>  mat[7] = src[7];
<a name="line105"></a>  mat[8] = src[8];
<a name="line106"></a>  return mat;
<a name="line107"></a>};
<a name="line108"></a>
<a name="line109"></a>
<a name="line110"></a>/**
<a name="line111"></a> * Initializes mat3f mat from mat3d src (typed as a Float64Array to
<a name="line112"></a> * avoid circular goog.requires).
<a name="line113"></a> *
<a name="line114"></a> * @param {goog.vec.mat3f.Type} mat The destination matrix.
<a name="line115"></a> * @param {Float64Array} src The source matrix.
<a name="line116"></a> * @return {!goog.vec.mat3f.Type} Return mat so that operations can be
<a name="line117"></a> *     chained together.
<a name="line118"></a> */
<a name="line119"></a>goog.vec.mat3f.setFromMat3d = function(mat, src) {
<a name="line120"></a>  mat[0] = src[0];
<a name="line121"></a>  mat[1] = src[1];
<a name="line122"></a>  mat[2] = src[2];
<a name="line123"></a>  mat[3] = src[3];
<a name="line124"></a>  mat[4] = src[4];
<a name="line125"></a>  mat[5] = src[5];
<a name="line126"></a>  mat[6] = src[6];
<a name="line127"></a>  mat[7] = src[7];
<a name="line128"></a>  mat[8] = src[8];
<a name="line129"></a>  return mat;
<a name="line130"></a>};
<a name="line131"></a>
<a name="line132"></a>
<a name="line133"></a>/**
<a name="line134"></a> * Initializes mat3f mat from Array src.
<a name="line135"></a> *
<a name="line136"></a> * @param {goog.vec.mat3f.Type} mat The destination matrix.
<a name="line137"></a> * @param {Array.&lt;number&gt;} src The source matrix.
<a name="line138"></a> * @return {!goog.vec.mat3f.Type} Return mat so that operations can be
<a name="line139"></a> *     chained together.
<a name="line140"></a> */
<a name="line141"></a>goog.vec.mat3f.setFromArray = function(mat, src) {
<a name="line142"></a>  mat[0] = src[0];
<a name="line143"></a>  mat[1] = src[1];
<a name="line144"></a>  mat[2] = src[2];
<a name="line145"></a>  mat[3] = src[3];
<a name="line146"></a>  mat[4] = src[4];
<a name="line147"></a>  mat[5] = src[5];
<a name="line148"></a>  mat[6] = src[6];
<a name="line149"></a>  mat[7] = src[7];
<a name="line150"></a>  mat[8] = src[8];
<a name="line151"></a>  return mat;
<a name="line152"></a>};
<a name="line153"></a>
<a name="line154"></a>
<a name="line155"></a>/**
<a name="line156"></a> * Retrieves the element at the requested row and column.
<a name="line157"></a> *
<a name="line158"></a> * @param {goog.vec.mat3f.Type} mat The matrix containing the value to
<a name="line159"></a> *     retrieve.
<a name="line160"></a> * @param {number} row The row index.
<a name="line161"></a> * @param {number} column The column index.
<a name="line162"></a> * @return {number} The element value at the requested row, column indices.
<a name="line163"></a> */
<a name="line164"></a>goog.vec.mat3f.getElement = function(mat, row, column) {
<a name="line165"></a>  return mat[row + column * 3];
<a name="line166"></a>};
<a name="line167"></a>
<a name="line168"></a>
<a name="line169"></a>/**
<a name="line170"></a> * Sets the element at the requested row and column.
<a name="line171"></a> *
<a name="line172"></a> * @param {goog.vec.mat3f.Type} mat The matrix containing the value to
<a name="line173"></a> *     retrieve.
<a name="line174"></a> * @param {number} row The row index.
<a name="line175"></a> * @param {number} column The column index.
<a name="line176"></a> * @param {number} value The value to set at the requested row, column.
<a name="line177"></a> * @return {!goog.vec.mat3f.Type} return mat so that operations can be
<a name="line178"></a> *     chained together.
<a name="line179"></a> */
<a name="line180"></a>goog.vec.mat3f.setElement = function(mat, row, column, value) {
<a name="line181"></a>  mat[row + column * 3] = value;
<a name="line182"></a>  return mat;
<a name="line183"></a>};
<a name="line184"></a>
<a name="line185"></a>
<a name="line186"></a>/**
<a name="line187"></a> * Sets the diagonal values of the matrix from the given values.
<a name="line188"></a> *
<a name="line189"></a> * @param {goog.vec.mat3f.Type} mat The matrix to receive the values.
<a name="line190"></a> * @param {number} v00 The values for (0, 0).
<a name="line191"></a> * @param {number} v11 The values for (1, 1).
<a name="line192"></a> * @param {number} v22 The values for (2, 2).
<a name="line193"></a> * @return {!goog.vec.mat3f.Type} return mat so that operations can be
<a name="line194"></a> *     chained together.
<a name="line195"></a> */
<a name="line196"></a>goog.vec.mat3f.setDiagonalValues = function(mat, v00, v11, v22) {
<a name="line197"></a>  mat[0] = v00;
<a name="line198"></a>  mat[4] = v11;
<a name="line199"></a>  mat[8] = v22;
<a name="line200"></a>  return mat;
<a name="line201"></a>};
<a name="line202"></a>
<a name="line203"></a>
<a name="line204"></a>/**
<a name="line205"></a> * Sets the diagonal values of the matrix from the given vector.
<a name="line206"></a> *
<a name="line207"></a> * @param {goog.vec.mat3f.Type} mat The matrix to receive the values.
<a name="line208"></a> * @param {goog.vec.vec3f.Type} vec The vector containing the values.
<a name="line209"></a> * @return {!goog.vec.mat3f.Type} return mat so that operations can be
<a name="line210"></a> *     chained together.
<a name="line211"></a> */
<a name="line212"></a>goog.vec.mat3f.setDiagonal = function(mat, vec) {
<a name="line213"></a>  mat[0] = vec[0];
<a name="line214"></a>  mat[4] = vec[1];
<a name="line215"></a>  mat[8] = vec[2];
<a name="line216"></a>  return mat;
<a name="line217"></a>};
<a name="line218"></a>
<a name="line219"></a>
<a name="line220"></a>/**
<a name="line221"></a> * Sets the specified column with the supplied values.
<a name="line222"></a> *
<a name="line223"></a> * @param {goog.vec.mat3f.Type} mat The matrix to recieve the values.
<a name="line224"></a> * @param {number} column The column index to set the values on.
<a name="line225"></a> * @param {number} v0 The value for row 0.
<a name="line226"></a> * @param {number} v1 The value for row 1.
<a name="line227"></a> * @param {number} v2 The value for row 2.
<a name="line228"></a> * @return {!goog.vec.mat3f.Type} return mat so that operations can be
<a name="line229"></a> *     chained together.
<a name="line230"></a> */
<a name="line231"></a>goog.vec.mat3f.setColumnValues = function(mat, column, v0, v1, v2) {
<a name="line232"></a>  var i = column * 3;
<a name="line233"></a>  mat[i] = v0;
<a name="line234"></a>  mat[i + 1] = v1;
<a name="line235"></a>  mat[i + 2] = v2;
<a name="line236"></a>  return mat;
<a name="line237"></a>};
<a name="line238"></a>
<a name="line239"></a>
<a name="line240"></a>/**
<a name="line241"></a> * Sets the specified column with the value from the supplied array.
<a name="line242"></a> *
<a name="line243"></a> * @param {goog.vec.mat3f.Type} mat The matrix to receive the values.
<a name="line244"></a> * @param {number} column The column index to set the values on.
<a name="line245"></a> * @param {goog.vec.vec3f.Type} vec The vector elements for the column.
<a name="line246"></a> * @return {!goog.vec.mat3f.Type} return mat so that operations can be
<a name="line247"></a> *     chained together.
<a name="line248"></a> */
<a name="line249"></a>goog.vec.mat3f.setColumn = function(mat, column, vec) {
<a name="line250"></a>  var i = column * 3;
<a name="line251"></a>  mat[i] = vec[0];
<a name="line252"></a>  mat[i + 1] = vec[1];
<a name="line253"></a>  mat[i + 2] = vec[2];
<a name="line254"></a>  return mat;
<a name="line255"></a>};
<a name="line256"></a>
<a name="line257"></a>
<a name="line258"></a>/**
<a name="line259"></a> * Retrieves the specified column from the matrix into the given vector
<a name="line260"></a> * array.
<a name="line261"></a> *
<a name="line262"></a> * @param {goog.vec.mat3f.Type} mat The matrix supplying the values.
<a name="line263"></a> * @param {number} column The column to get the values from.
<a name="line264"></a> * @param {goog.vec.vec3f.Type} vec The vector elements to receive the
<a name="line265"></a> *     column.
<a name="line266"></a> * @return {!goog.vec.vec3f.Type} return vec so that operations can be
<a name="line267"></a> *     chained together.
<a name="line268"></a> */
<a name="line269"></a>goog.vec.mat3f.getColumn = function(mat, column, vec) {
<a name="line270"></a>  var i = column * 3;
<a name="line271"></a>  vec[0] = mat[i];
<a name="line272"></a>  vec[1] = mat[i + 1];
<a name="line273"></a>  vec[2] = mat[i + 2];
<a name="line274"></a>  return vec;
<a name="line275"></a>};
<a name="line276"></a>
<a name="line277"></a>
<a name="line278"></a>/**
<a name="line279"></a> * Sets the columns of the matrix from the set of vector elements.
<a name="line280"></a> *
<a name="line281"></a> * @param {goog.vec.mat3f.Type} mat The matrix to receive the values.
<a name="line282"></a> * @param {goog.vec.vec3f.Type} vec0 The values for column 0.
<a name="line283"></a> * @param {goog.vec.vec3f.Type} vec1 The values for column 1.
<a name="line284"></a> * @param {goog.vec.vec3f.Type} vec2 The values for column 2.
<a name="line285"></a> * @return {!goog.vec.mat3f.Type} return mat so that operations can be
<a name="line286"></a> *     chained together.
<a name="line287"></a> */
<a name="line288"></a>goog.vec.mat3f.setColumns = function(mat, vec0, vec1, vec2) {
<a name="line289"></a>  goog.vec.mat3f.setColumn(mat, 0, vec0);
<a name="line290"></a>  goog.vec.mat3f.setColumn(mat, 1, vec1);
<a name="line291"></a>  goog.vec.mat3f.setColumn(mat, 2, vec2);
<a name="line292"></a>  return /** @type {!goog.vec.mat3f.Type} */(mat);
<a name="line293"></a>};
<a name="line294"></a>
<a name="line295"></a>
<a name="line296"></a>/**
<a name="line297"></a> * Retrieves the column values from the given matrix into the given vector
<a name="line298"></a> * elements.
<a name="line299"></a> *
<a name="line300"></a> * @param {goog.vec.mat3f.Type} mat The matrix supplying the columns.
<a name="line301"></a> * @param {goog.vec.vec3f.Type} vec0 The vector to receive column 0.
<a name="line302"></a> * @param {goog.vec.vec3f.Type} vec1 The vector to receive column 1.
<a name="line303"></a> * @param {goog.vec.vec3f.Type} vec2 The vector to receive column 2.
<a name="line304"></a> */
<a name="line305"></a>goog.vec.mat3f.getColumns = function(mat, vec0, vec1, vec2) {
<a name="line306"></a>  goog.vec.mat3f.getColumn(mat, 0, vec0);
<a name="line307"></a>  goog.vec.mat3f.getColumn(mat, 1, vec1);
<a name="line308"></a>  goog.vec.mat3f.getColumn(mat, 2, vec2);
<a name="line309"></a>};
<a name="line310"></a>
<a name="line311"></a>
<a name="line312"></a>/**
<a name="line313"></a> * Sets the row values from the supplied values.
<a name="line314"></a> *
<a name="line315"></a> * @param {goog.vec.mat3f.Type} mat The matrix to receive the values.
<a name="line316"></a> * @param {number} row The index of the row to receive the values.
<a name="line317"></a> * @param {number} v0 The value for column 0.
<a name="line318"></a> * @param {number} v1 The value for column 1.
<a name="line319"></a> * @param {number} v2 The value for column 2.
<a name="line320"></a> * @return {!goog.vec.mat3f.Type} return mat so that operations can be
<a name="line321"></a> *     chained together.
<a name="line322"></a> */
<a name="line323"></a>goog.vec.mat3f.setRowValues = function(mat, row, v0, v1, v2) {
<a name="line324"></a>  mat[row] = v0;
<a name="line325"></a>  mat[row + 3] = v1;
<a name="line326"></a>  mat[row + 6] = v2;
<a name="line327"></a>  return mat;
<a name="line328"></a>};
<a name="line329"></a>
<a name="line330"></a>
<a name="line331"></a>/**
<a name="line332"></a> * Sets the row values from the supplied vector.
<a name="line333"></a> *
<a name="line334"></a> * @param {goog.vec.mat3f.Type} mat The matrix to receive the row values.
<a name="line335"></a> * @param {number} row The index of the row.
<a name="line336"></a> * @param {goog.vec.vec3f.Type} vec The vector containing the values.
<a name="line337"></a> * @return {!goog.vec.mat3f.Type} return mat so that operations can be
<a name="line338"></a> *     chained together.
<a name="line339"></a> */
<a name="line340"></a>goog.vec.mat3f.setRow = function(mat, row, vec) {
<a name="line341"></a>  mat[row] = vec[0];
<a name="line342"></a>  mat[row + 3] = vec[1];
<a name="line343"></a>  mat[row + 6] = vec[2];
<a name="line344"></a>  return mat;
<a name="line345"></a>};
<a name="line346"></a>
<a name="line347"></a>
<a name="line348"></a>/**
<a name="line349"></a> * Retrieves the row values into the given vector.
<a name="line350"></a> *
<a name="line351"></a> * @param {goog.vec.mat3f.Type} mat The matrix supplying the values.
<a name="line352"></a> * @param {number} row The index of the row supplying the values.
<a name="line353"></a> * @param {goog.vec.vec3f.Type} vec The vector to receive the row.
<a name="line354"></a> * @return {!goog.vec.vec3f.Type} return vec so that operations can be
<a name="line355"></a> *     chained together.
<a name="line356"></a> */
<a name="line357"></a>goog.vec.mat3f.getRow = function(mat, row, vec) {
<a name="line358"></a>  vec[0] = mat[row];
<a name="line359"></a>  vec[1] = mat[row + 3];
<a name="line360"></a>  vec[2] = mat[row + 6];
<a name="line361"></a>  return vec;
<a name="line362"></a>};
<a name="line363"></a>
<a name="line364"></a>
<a name="line365"></a>/**
<a name="line366"></a> * Sets the rows of the matrix from the supplied vectors.
<a name="line367"></a> *
<a name="line368"></a> * @param {goog.vec.mat3f.Type} mat The matrix to receive the values.
<a name="line369"></a> * @param {goog.vec.vec3f.Type} vec0 The values for row 0.
<a name="line370"></a> * @param {goog.vec.vec3f.Type} vec1 The values for row 1.
<a name="line371"></a> * @param {goog.vec.vec3f.Type} vec2 The values for row 2.
<a name="line372"></a> * @return {!goog.vec.mat3f.Type} return mat so that operations can be
<a name="line373"></a> *     chained together.
<a name="line374"></a> */
<a name="line375"></a>goog.vec.mat3f.setRows = function(mat, vec0, vec1, vec2) {
<a name="line376"></a>  goog.vec.mat3f.setRow(mat, 0, vec0);
<a name="line377"></a>  goog.vec.mat3f.setRow(mat, 1, vec1);
<a name="line378"></a>  goog.vec.mat3f.setRow(mat, 2, vec2);
<a name="line379"></a>  return /** @type {!goog.vec.mat3f.Type} */(mat);
<a name="line380"></a>};
<a name="line381"></a>
<a name="line382"></a>
<a name="line383"></a>/**
<a name="line384"></a> * Retrieves the rows of the matrix into the supplied vectors.
<a name="line385"></a> *
<a name="line386"></a> * @param {goog.vec.mat3f.Type} mat The matrix to supplying the values.
<a name="line387"></a> * @param {goog.vec.vec3f.Type} vec0 The vector to receive row 0.
<a name="line388"></a> * @param {goog.vec.vec3f.Type} vec1 The vector to receive row 1.
<a name="line389"></a> * @param {goog.vec.vec3f.Type} vec2 The vector to receive row 2.
<a name="line390"></a> */
<a name="line391"></a>goog.vec.mat3f.getRows = function(mat, vec0, vec1, vec2) {
<a name="line392"></a>  goog.vec.mat3f.getRow(mat, 0, vec0);
<a name="line393"></a>  goog.vec.mat3f.getRow(mat, 1, vec1);
<a name="line394"></a>  goog.vec.mat3f.getRow(mat, 2, vec2);
<a name="line395"></a>};
<a name="line396"></a>
<a name="line397"></a>
<a name="line398"></a>/**
<a name="line399"></a> * Makes the given 3x3 matrix the zero matrix.
<a name="line400"></a> *
<a name="line401"></a> * @param {goog.vec.mat3f.Type} mat The matrix.
<a name="line402"></a> * @return {!goog.vec.mat3f.Type} return mat so operations can be chained.
<a name="line403"></a> */
<a name="line404"></a>goog.vec.mat3f.makeZero = function(mat) {
<a name="line405"></a>  mat[0] = 0;
<a name="line406"></a>  mat[1] = 0;
<a name="line407"></a>  mat[2] = 0;
<a name="line408"></a>  mat[3] = 0;
<a name="line409"></a>  mat[4] = 0;
<a name="line410"></a>  mat[5] = 0;
<a name="line411"></a>  mat[6] = 0;
<a name="line412"></a>  mat[7] = 0;
<a name="line413"></a>  mat[8] = 0;
<a name="line414"></a>  return mat;
<a name="line415"></a>};
<a name="line416"></a>
<a name="line417"></a>
<a name="line418"></a>/**
<a name="line419"></a> * Makes the given 3x3 matrix the identity matrix.
<a name="line420"></a> *
<a name="line421"></a> * @param {goog.vec.mat3f.Type} mat The matrix.
<a name="line422"></a> * @return {!goog.vec.mat3f.Type} return mat so operations can be chained.
<a name="line423"></a> */
<a name="line424"></a>goog.vec.mat3f.makeIdentity = function(mat) {
<a name="line425"></a>  mat[0] = 1;
<a name="line426"></a>  mat[1] = 0;
<a name="line427"></a>  mat[2] = 0;
<a name="line428"></a>  mat[3] = 0;
<a name="line429"></a>  mat[4] = 1;
<a name="line430"></a>  mat[5] = 0;
<a name="line431"></a>  mat[6] = 0;
<a name="line432"></a>  mat[7] = 0;
<a name="line433"></a>  mat[8] = 1;
<a name="line434"></a>  return mat;
<a name="line435"></a>};
<a name="line436"></a>
<a name="line437"></a>
<a name="line438"></a>/**
<a name="line439"></a> * Performs a per-component addition of the matrices mat0 and mat1, storing
<a name="line440"></a> * the result into resultMat.
<a name="line441"></a> *
<a name="line442"></a> * @param {goog.vec.mat3f.Type} mat0 The first addend.
<a name="line443"></a> * @param {goog.vec.mat3f.Type} mat1 The second addend.
<a name="line444"></a> * @param {goog.vec.mat3f.Type} resultMat The matrix to
<a name="line445"></a> *     receive the results (may be either mat0 or mat1).
<a name="line446"></a> * @return {!goog.vec.mat3f.Type} return resultMat so that operations can be
<a name="line447"></a> *     chained together.
<a name="line448"></a> */
<a name="line449"></a>goog.vec.mat3f.addMat = function(mat0, mat1, resultMat) {
<a name="line450"></a>  resultMat[0] = mat0[0] + mat1[0];
<a name="line451"></a>  resultMat[1] = mat0[1] + mat1[1];
<a name="line452"></a>  resultMat[2] = mat0[2] + mat1[2];
<a name="line453"></a>  resultMat[3] = mat0[3] + mat1[3];
<a name="line454"></a>  resultMat[4] = mat0[4] + mat1[4];
<a name="line455"></a>  resultMat[5] = mat0[5] + mat1[5];
<a name="line456"></a>  resultMat[6] = mat0[6] + mat1[6];
<a name="line457"></a>  resultMat[7] = mat0[7] + mat1[7];
<a name="line458"></a>  resultMat[8] = mat0[8] + mat1[8];
<a name="line459"></a>  return resultMat;
<a name="line460"></a>};
<a name="line461"></a>
<a name="line462"></a>
<a name="line463"></a>/**
<a name="line464"></a> * Performs a per-component subtraction of the matrices mat0 and mat1,
<a name="line465"></a> * storing the result into resultMat.
<a name="line466"></a> *
<a name="line467"></a> * @param {goog.vec.mat3f.Type} mat0 The minuend.
<a name="line468"></a> * @param {goog.vec.mat3f.Type} mat1 The subtrahend.
<a name="line469"></a> * @param {goog.vec.mat3f.Type} resultMat The matrix to receive
<a name="line470"></a> *     the results (may be either mat0 or mat1).
<a name="line471"></a> * @return {!goog.vec.mat3f.Type} return resultMat so that operations can be
<a name="line472"></a> *     chained together.
<a name="line473"></a> */
<a name="line474"></a>goog.vec.mat3f.subMat = function(mat0, mat1, resultMat) {
<a name="line475"></a>  resultMat[0] = mat0[0] - mat1[0];
<a name="line476"></a>  resultMat[1] = mat0[1] - mat1[1];
<a name="line477"></a>  resultMat[2] = mat0[2] - mat1[2];
<a name="line478"></a>  resultMat[3] = mat0[3] - mat1[3];
<a name="line479"></a>  resultMat[4] = mat0[4] - mat1[4];
<a name="line480"></a>  resultMat[5] = mat0[5] - mat1[5];
<a name="line481"></a>  resultMat[6] = mat0[6] - mat1[6];
<a name="line482"></a>  resultMat[7] = mat0[7] - mat1[7];
<a name="line483"></a>  resultMat[8] = mat0[8] - mat1[8];
<a name="line484"></a>  return resultMat;
<a name="line485"></a>};
<a name="line486"></a>
<a name="line487"></a>
<a name="line488"></a>/**
<a name="line489"></a> * Multiplies matrix mat0 with the given scalar, storing the result
<a name="line490"></a> * into resultMat.
<a name="line491"></a> *
<a name="line492"></a> * @param {goog.vec.mat3f.Type} mat The matrix.
<a name="line493"></a> * @param {number} scalar The scalar value to multiple to each element of mat.
<a name="line494"></a> * @param {goog.vec.mat3f.Type} resultMat The matrix to receive
<a name="line495"></a> *     the results (may be mat).
<a name="line496"></a> * @return {!goog.vec.mat3f.Type} return resultMat so that operations can be
<a name="line497"></a> *     chained together.
<a name="line498"></a> */
<a name="line499"></a>goog.vec.mat3f.multScalar = function(mat, scalar, resultMat) {
<a name="line500"></a>  resultMat[0] = mat[0] * scalar;
<a name="line501"></a>  resultMat[1] = mat[1] * scalar;
<a name="line502"></a>  resultMat[2] = mat[2] * scalar;
<a name="line503"></a>  resultMat[3] = mat[3] * scalar;
<a name="line504"></a>  resultMat[4] = mat[4] * scalar;
<a name="line505"></a>  resultMat[5] = mat[5] * scalar;
<a name="line506"></a>  resultMat[6] = mat[6] * scalar;
<a name="line507"></a>  resultMat[7] = mat[7] * scalar;
<a name="line508"></a>  resultMat[8] = mat[8] * scalar;
<a name="line509"></a>  return resultMat;
<a name="line510"></a>};
<a name="line511"></a>
<a name="line512"></a>
<a name="line513"></a>/**
<a name="line514"></a> * Multiplies the two matrices mat0 and mat1 using matrix multiplication,
<a name="line515"></a> * storing the result into resultMat.
<a name="line516"></a> *
<a name="line517"></a> * @param {goog.vec.mat3f.Type} mat0 The first (left hand) matrix.
<a name="line518"></a> * @param {goog.vec.mat3f.Type} mat1 The second (right hand) matrix.
<a name="line519"></a> * @param {goog.vec.mat3f.Type} resultMat The matrix to receive
<a name="line520"></a> *     the results (may be either mat0 or mat1).
<a name="line521"></a> * @return {!goog.vec.mat3f.Type} return resultMat so that operations can be
<a name="line522"></a> *     chained together.
<a name="line523"></a> */
<a name="line524"></a>goog.vec.mat3f.multMat = function(mat0, mat1, resultMat) {
<a name="line525"></a>  var a00 = mat0[0], a10 = mat0[1], a20 = mat0[2];
<a name="line526"></a>  var a01 = mat0[3], a11 = mat0[4], a21 = mat0[5];
<a name="line527"></a>  var a02 = mat0[6], a12 = mat0[7], a22 = mat0[8];
<a name="line528"></a>
<a name="line529"></a>  var b00 = mat1[0], b10 = mat1[1], b20 = mat1[2];
<a name="line530"></a>  var b01 = mat1[3], b11 = mat1[4], b21 = mat1[5];
<a name="line531"></a>  var b02 = mat1[6], b12 = mat1[7], b22 = mat1[8];
<a name="line532"></a>
<a name="line533"></a>  resultMat[0] = a00 * b00 + a01 * b10 + a02 * b20;
<a name="line534"></a>  resultMat[1] = a10 * b00 + a11 * b10 + a12 * b20;
<a name="line535"></a>  resultMat[2] = a20 * b00 + a21 * b10 + a22 * b20;
<a name="line536"></a>  resultMat[3] = a00 * b01 + a01 * b11 + a02 * b21;
<a name="line537"></a>  resultMat[4] = a10 * b01 + a11 * b11 + a12 * b21;
<a name="line538"></a>  resultMat[5] = a20 * b01 + a21 * b11 + a22 * b21;
<a name="line539"></a>  resultMat[6] = a00 * b02 + a01 * b12 + a02 * b22;
<a name="line540"></a>  resultMat[7] = a10 * b02 + a11 * b12 + a12 * b22;
<a name="line541"></a>  resultMat[8] = a20 * b02 + a21 * b12 + a22 * b22;
<a name="line542"></a>  return resultMat;
<a name="line543"></a>};
<a name="line544"></a>
<a name="line545"></a>
<a name="line546"></a>/**
<a name="line547"></a> * Transposes the given matrix mat storing the result into resultMat.
<a name="line548"></a> *
<a name="line549"></a> * @param {goog.vec.mat3f.Type} mat The matrix to transpose.
<a name="line550"></a> * @param {goog.vec.mat3f.Type} resultMat The matrix to receive
<a name="line551"></a> *     the results (may be mat).
<a name="line552"></a> * @return {!goog.vec.mat3f.Type} return resultMat so that operations can be
<a name="line553"></a> *     chained together.
<a name="line554"></a> */
<a name="line555"></a>goog.vec.mat3f.transpose = function(mat, resultMat) {
<a name="line556"></a>  if (resultMat == mat) {
<a name="line557"></a>    var a10 = mat[1], a20 = mat[2], a21 = mat[5];
<a name="line558"></a>    resultMat[1] = mat[3];
<a name="line559"></a>    resultMat[2] = mat[6];
<a name="line560"></a>    resultMat[3] = a10;
<a name="line561"></a>    resultMat[5] = mat[7];
<a name="line562"></a>    resultMat[6] = a20;
<a name="line563"></a>    resultMat[7] = a21;
<a name="line564"></a>  } else {
<a name="line565"></a>    resultMat[0] = mat[0];
<a name="line566"></a>    resultMat[1] = mat[3];
<a name="line567"></a>    resultMat[2] = mat[6];
<a name="line568"></a>    resultMat[3] = mat[1];
<a name="line569"></a>    resultMat[4] = mat[4];
<a name="line570"></a>    resultMat[5] = mat[7];
<a name="line571"></a>    resultMat[6] = mat[2];
<a name="line572"></a>    resultMat[7] = mat[5];
<a name="line573"></a>    resultMat[8] = mat[8];
<a name="line574"></a>  }
<a name="line575"></a>  return resultMat;
<a name="line576"></a>};
<a name="line577"></a>
<a name="line578"></a>
<a name="line579"></a>/**
<a name="line580"></a> * Computes the inverse of mat0 storing the result into resultMat. If the
<a name="line581"></a> * inverse is defined, this function returns true, false otherwise.
<a name="line582"></a> *
<a name="line583"></a> * @param {goog.vec.mat3f.Type} mat0 The matrix to invert.
<a name="line584"></a> * @param {goog.vec.mat3f.Type} resultMat The matrix to receive
<a name="line585"></a> *     the result (may be mat0).
<a name="line586"></a> * @return {boolean} True if the inverse is defined. If false is returned,
<a name="line587"></a> *     resultMat is not modified.
<a name="line588"></a> */
<a name="line589"></a>goog.vec.mat3f.invert = function(mat0, resultMat) {
<a name="line590"></a>  var a00 = mat0[0], a10 = mat0[1], a20 = mat0[2];
<a name="line591"></a>  var a01 = mat0[3], a11 = mat0[4], a21 = mat0[5];
<a name="line592"></a>  var a02 = mat0[6], a12 = mat0[7], a22 = mat0[8];
<a name="line593"></a>
<a name="line594"></a>  var t00 = a11 * a22 - a12 * a21;
<a name="line595"></a>  var t10 = a12 * a20 - a10 * a22;
<a name="line596"></a>  var t20 = a10 * a21 - a11 * a20;
<a name="line597"></a>  var det = a00 * t00 + a01 * t10 + a02 * t20;
<a name="line598"></a>  if (det == 0) {
<a name="line599"></a>    return false;
<a name="line600"></a>  }
<a name="line601"></a>
<a name="line602"></a>  var idet = 1 / det;
<a name="line603"></a>  resultMat[0] = t00 * idet;
<a name="line604"></a>  resultMat[3] = (a02 * a21 - a01 * a22) * idet;
<a name="line605"></a>  resultMat[6] = (a01 * a12 - a02 * a11) * idet;
<a name="line606"></a>
<a name="line607"></a>  resultMat[1] = t10 * idet;
<a name="line608"></a>  resultMat[4] = (a00 * a22 - a02 * a20) * idet;
<a name="line609"></a>  resultMat[7] = (a02 * a10 - a00 * a12) * idet;
<a name="line610"></a>
<a name="line611"></a>  resultMat[2] = t20 * idet;
<a name="line612"></a>  resultMat[5] = (a01 * a20 - a00 * a21) * idet;
<a name="line613"></a>  resultMat[8] = (a00 * a11 - a01 * a10) * idet;
<a name="line614"></a>  return true;
<a name="line615"></a>};
<a name="line616"></a>
<a name="line617"></a>
<a name="line618"></a>/**
<a name="line619"></a> * Returns true if the components of mat0 are equal to the components of mat1.
<a name="line620"></a> *
<a name="line621"></a> * @param {goog.vec.mat3f.Type} mat0 The first matrix.
<a name="line622"></a> * @param {goog.vec.mat3f.Type} mat1 The second matrix.
<a name="line623"></a> * @return {boolean} True if the the two matrices are equivalent.
<a name="line624"></a> */
<a name="line625"></a>goog.vec.mat3f.equals = function(mat0, mat1) {
<a name="line626"></a>  return mat0.length == mat1.length &amp;&amp;
<a name="line627"></a>      mat0[0] == mat1[0] &amp;&amp; mat0[1] == mat1[1] &amp;&amp; mat0[2] == mat1[2] &amp;&amp;
<a name="line628"></a>      mat0[3] == mat1[3] &amp;&amp; mat0[4] == mat1[4] &amp;&amp; mat0[5] == mat1[5] &amp;&amp;
<a name="line629"></a>      mat0[6] == mat1[6] &amp;&amp; mat0[7] == mat1[7] &amp;&amp; mat0[8] == mat1[8];
<a name="line630"></a>};
<a name="line631"></a>
<a name="line632"></a>
<a name="line633"></a>/**
<a name="line634"></a> * Transforms the given vector with the given matrix storing the resulting,
<a name="line635"></a> * transformed matrix into resultVec.
<a name="line636"></a> *
<a name="line637"></a> * @param {goog.vec.mat3f.Type} mat The matrix supplying the transformation.
<a name="line638"></a> * @param {goog.vec.vec3f.Type} vec The vector to transform.
<a name="line639"></a> * @param {goog.vec.vec3f.Type} resultVec The vector to
<a name="line640"></a> *     receive the results (may be vec).
<a name="line641"></a> * @return {!goog.vec.vec3f.Type} return resultVec so that operations can be
<a name="line642"></a> *     chained together.
<a name="line643"></a> */
<a name="line644"></a>goog.vec.mat3f.multVec3 = function(mat, vec, resultVec) {
<a name="line645"></a>  var x = vec[0], y = vec[1], z = vec[2];
<a name="line646"></a>  resultVec[0] = x * mat[0] + y * mat[3] + z * mat[6];
<a name="line647"></a>  resultVec[1] = x * mat[1] + y * mat[4] + z * mat[7];
<a name="line648"></a>  resultVec[2] = x * mat[2] + y * mat[5] + z * mat[8];
<a name="line649"></a>  return resultVec;
<a name="line650"></a>};
<a name="line651"></a>
<a name="line652"></a>
<a name="line653"></a>/**
<a name="line654"></a> * Makes the given 3x3 matrix a translation matrix with x and y
<a name="line655"></a> * translation values.
<a name="line656"></a> *
<a name="line657"></a> * @param {goog.vec.mat3f.Type} mat The matrix.
<a name="line658"></a> * @param {number} x The translation along the x axis.
<a name="line659"></a> * @param {number} y The translation along the y axis.
<a name="line660"></a> * @return {!goog.vec.mat3f.Type} return mat so that operations can be
<a name="line661"></a> *     chained.
<a name="line662"></a> */
<a name="line663"></a>goog.vec.mat3f.makeTranslate = function(mat, x, y) {
<a name="line664"></a>  mat[0] = 1;
<a name="line665"></a>  mat[1] = 0;
<a name="line666"></a>  mat[2] = 0;
<a name="line667"></a>  mat[3] = 0;
<a name="line668"></a>  mat[4] = 1;
<a name="line669"></a>  mat[5] = 0;
<a name="line670"></a>  mat[6] = x;
<a name="line671"></a>  mat[7] = y;
<a name="line672"></a>  mat[8] = 1;
<a name="line673"></a>  return mat;
<a name="line674"></a>};
<a name="line675"></a>
<a name="line676"></a>
<a name="line677"></a>/**
<a name="line678"></a> * Makes the given 3x3 matrix a scale matrix with x, y, and z scale factors.
<a name="line679"></a> *
<a name="line680"></a> * @param {goog.vec.mat3f.Type} mat The 3x3 (9-element) matrix
<a name="line681"></a> *     array to receive the new scale matrix.
<a name="line682"></a> * @param {number} x The scale along the x axis.
<a name="line683"></a> * @param {number} y The scale along the y axis.
<a name="line684"></a> * @param {number} z The scale along the z axis.
<a name="line685"></a> * @return {!goog.vec.mat3f.Type} return mat so that operations can be
<a name="line686"></a> *     chained.
<a name="line687"></a> */
<a name="line688"></a>goog.vec.mat3f.makeScale = function(mat, x, y, z) {
<a name="line689"></a>  mat[0] = x;
<a name="line690"></a>  mat[1] = 0;
<a name="line691"></a>  mat[2] = 0;
<a name="line692"></a>  mat[3] = 0;
<a name="line693"></a>  mat[4] = y;
<a name="line694"></a>  mat[5] = 0;
<a name="line695"></a>  mat[6] = 0;
<a name="line696"></a>  mat[7] = 0;
<a name="line697"></a>  mat[8] = z;
<a name="line698"></a>  return mat;
<a name="line699"></a>};
<a name="line700"></a>
<a name="line701"></a>
<a name="line702"></a>/**
<a name="line703"></a> * Makes the given 3x3 matrix a rotation matrix with the given rotation
<a name="line704"></a> * angle about the axis defined by the vector (ax, ay, az).
<a name="line705"></a> *
<a name="line706"></a> * @param {goog.vec.mat3f.Type} mat The matrix.
<a name="line707"></a> * @param {number} angle The rotation angle in radians.
<a name="line708"></a> * @param {number} ax The x component of the rotation axis.
<a name="line709"></a> * @param {number} ay The y component of the rotation axis.
<a name="line710"></a> * @param {number} az The z component of the rotation axis.
<a name="line711"></a> * @return {!goog.vec.mat3f.Type} return mat so that operations can be
<a name="line712"></a> *     chained.
<a name="line713"></a> */
<a name="line714"></a>goog.vec.mat3f.makeRotate = function(mat, angle, ax, ay, az) {
<a name="line715"></a>  var c = Math.cos(angle);
<a name="line716"></a>  var d = 1 - c;
<a name="line717"></a>  var s = Math.sin(angle);
<a name="line718"></a>
<a name="line719"></a>  mat[0] = ax * ax * d + c;
<a name="line720"></a>  mat[1] = ax * ay * d + az * s;
<a name="line721"></a>  mat[2] = ax * az * d - ay * s;
<a name="line722"></a>  mat[3] = ax * ay * d - az * s;
<a name="line723"></a>  mat[4] = ay * ay * d + c;
<a name="line724"></a>  mat[5] = ay * az * d + ax * s;
<a name="line725"></a>  mat[6] = ax * az * d + ay * s;
<a name="line726"></a>  mat[7] = ay * az * d - ax * s;
<a name="line727"></a>  mat[8] = az * az * d + c;
<a name="line728"></a>
<a name="line729"></a>  return mat;
<a name="line730"></a>};
<a name="line731"></a>
<a name="line732"></a>
<a name="line733"></a>/**
<a name="line734"></a> * Makes the given 3x3 matrix a rotation matrix with the given rotation
<a name="line735"></a> * angle about the X axis.
<a name="line736"></a> *
<a name="line737"></a> * @param {goog.vec.mat3f.Type} mat The matrix.
<a name="line738"></a> * @param {number} angle The rotation angle in radians.
<a name="line739"></a> * @return {!goog.vec.mat3f.Type} return mat so that operations can be
<a name="line740"></a> *     chained.
<a name="line741"></a> */
<a name="line742"></a>goog.vec.mat3f.makeRotateX = function(mat, angle) {
<a name="line743"></a>  var c = Math.cos(angle);
<a name="line744"></a>  var s = Math.sin(angle);
<a name="line745"></a>
<a name="line746"></a>  mat[0] = 1;
<a name="line747"></a>  mat[1] = 0;
<a name="line748"></a>  mat[2] = 0;
<a name="line749"></a>  mat[3] = 0;
<a name="line750"></a>  mat[4] = c;
<a name="line751"></a>  mat[5] = s;
<a name="line752"></a>  mat[6] = 0;
<a name="line753"></a>  mat[7] = -s;
<a name="line754"></a>  mat[8] = c;
<a name="line755"></a>
<a name="line756"></a>  return mat;
<a name="line757"></a>};
<a name="line758"></a>
<a name="line759"></a>
<a name="line760"></a>/**
<a name="line761"></a> * Makes the given 3x3 matrix a rotation matrix with the given rotation
<a name="line762"></a> * angle about the Y axis.
<a name="line763"></a> *
<a name="line764"></a> * @param {goog.vec.mat3f.Type} mat The matrix.
<a name="line765"></a> * @param {number} angle The rotation angle in radians.
<a name="line766"></a> * @return {!goog.vec.mat3f.Type} return mat so that operations can be
<a name="line767"></a> *     chained.
<a name="line768"></a> */
<a name="line769"></a>goog.vec.mat3f.makeRotateY = function(mat, angle) {
<a name="line770"></a>  var c = Math.cos(angle);
<a name="line771"></a>  var s = Math.sin(angle);
<a name="line772"></a>
<a name="line773"></a>  mat[0] = c;
<a name="line774"></a>  mat[1] = 0;
<a name="line775"></a>  mat[2] = -s;
<a name="line776"></a>  mat[3] = 0;
<a name="line777"></a>  mat[4] = 1;
<a name="line778"></a>  mat[5] = 0;
<a name="line779"></a>  mat[6] = s;
<a name="line780"></a>  mat[7] = 0;
<a name="line781"></a>  mat[8] = c;
<a name="line782"></a>
<a name="line783"></a>  return mat;
<a name="line784"></a>};
<a name="line785"></a>
<a name="line786"></a>
<a name="line787"></a>/**
<a name="line788"></a> * Makes the given 3x3 matrix a rotation matrix with the given rotation
<a name="line789"></a> * angle about the Z axis.
<a name="line790"></a> *
<a name="line791"></a> * @param {goog.vec.mat3f.Type} mat The matrix.
<a name="line792"></a> * @param {number} angle The rotation angle in radians.
<a name="line793"></a> * @return {!goog.vec.mat3f.Type} return mat so that operations can be
<a name="line794"></a> *     chained.
<a name="line795"></a> */
<a name="line796"></a>goog.vec.mat3f.makeRotateZ = function(mat, angle) {
<a name="line797"></a>  var c = Math.cos(angle);
<a name="line798"></a>  var s = Math.sin(angle);
<a name="line799"></a>
<a name="line800"></a>  mat[0] = c;
<a name="line801"></a>  mat[1] = s;
<a name="line802"></a>  mat[2] = 0;
<a name="line803"></a>  mat[3] = -s;
<a name="line804"></a>  mat[4] = c;
<a name="line805"></a>  mat[5] = 0;
<a name="line806"></a>  mat[6] = 0;
<a name="line807"></a>  mat[7] = 0;
<a name="line808"></a>  mat[8] = 1;
<a name="line809"></a>
<a name="line810"></a>  return mat;
<a name="line811"></a>};
<a name="line812"></a>
<a name="line813"></a>
<a name="line814"></a>/**
<a name="line815"></a> * Rotate the given matrix by angle about the x,y,z axis.  Equivalent to:
<a name="line816"></a> * goog.vec.mat3f.multMat(
<a name="line817"></a> *     mat,
<a name="line818"></a> *     goog.vec.mat3f.makeRotate(goog.vec.mat3f.create(), angle, x, y, z),
<a name="line819"></a> *     mat);
<a name="line820"></a> *
<a name="line821"></a> * @param {goog.vec.mat3f.Type} mat The matrix.
<a name="line822"></a> * @param {number} angle The angle in radians.
<a name="line823"></a> * @param {number} x The x component of the rotation axis.
<a name="line824"></a> * @param {number} y The y component of the rotation axis.
<a name="line825"></a> * @param {number} z The z component of the rotation axis.
<a name="line826"></a> * @return {!goog.vec.mat3f.Type} return mat so that operations can be
<a name="line827"></a> *     chained.
<a name="line828"></a> */
<a name="line829"></a>goog.vec.mat3f.rotate = function(mat, angle, x, y, z) {
<a name="line830"></a>  var m00 = mat[0], m10 = mat[1], m20 = mat[2];
<a name="line831"></a>  var m01 = mat[3], m11 = mat[4], m21 = mat[5];
<a name="line832"></a>  var m02 = mat[6], m12 = mat[7], m22 = mat[8];
<a name="line833"></a>
<a name="line834"></a>  var cosAngle = Math.cos(angle);
<a name="line835"></a>  var sinAngle = Math.sin(angle);
<a name="line836"></a>  var diffCosAngle = 1 - cosAngle;
<a name="line837"></a>  var r00 = x * x * diffCosAngle + cosAngle;
<a name="line838"></a>  var r10 = x * y * diffCosAngle + z * sinAngle;
<a name="line839"></a>  var r20 = x * z * diffCosAngle - y * sinAngle;
<a name="line840"></a>
<a name="line841"></a>  var r01 = x * y * diffCosAngle - z * sinAngle;
<a name="line842"></a>  var r11 = y * y * diffCosAngle + cosAngle;
<a name="line843"></a>  var r21 = y * z * diffCosAngle + x * sinAngle;
<a name="line844"></a>
<a name="line845"></a>  var r02 = x * z * diffCosAngle + y * sinAngle;
<a name="line846"></a>  var r12 = y * z * diffCosAngle - x * sinAngle;
<a name="line847"></a>  var r22 = z * z * diffCosAngle + cosAngle;
<a name="line848"></a>
<a name="line849"></a>  mat[0] = m00 * r00 + m01 * r10 + m02 * r20;
<a name="line850"></a>  mat[1] = m10 * r00 + m11 * r10 + m12 * r20;
<a name="line851"></a>  mat[2] = m20 * r00 + m21 * r10 + m22 * r20;
<a name="line852"></a>  mat[3] = m00 * r01 + m01 * r11 + m02 * r21;
<a name="line853"></a>  mat[4] = m10 * r01 + m11 * r11 + m12 * r21;
<a name="line854"></a>  mat[5] = m20 * r01 + m21 * r11 + m22 * r21;
<a name="line855"></a>  mat[6] = m00 * r02 + m01 * r12 + m02 * r22;
<a name="line856"></a>  mat[7] = m10 * r02 + m11 * r12 + m12 * r22;
<a name="line857"></a>  mat[8] = m20 * r02 + m21 * r12 + m22 * r22;
<a name="line858"></a>
<a name="line859"></a>  return mat;
<a name="line860"></a>};
<a name="line861"></a>
<a name="line862"></a>
<a name="line863"></a>/**
<a name="line864"></a> * Rotate the given matrix by angle about the x axis.  Equivalent to:
<a name="line865"></a> * goog.vec.mat3f.multMat(
<a name="line866"></a> *     mat,
<a name="line867"></a> *     goog.vec.mat3f.makeRotateX(goog.vec.mat3f.create(), angle),
<a name="line868"></a> *     mat);
<a name="line869"></a> *
<a name="line870"></a> * @param {goog.vec.mat3f.Type} mat The matrix.
<a name="line871"></a> * @param {number} angle The angle in radians.
<a name="line872"></a> * @return {!goog.vec.mat3f.Type} return mat so that operations can be
<a name="line873"></a> *     chained.
<a name="line874"></a> */
<a name="line875"></a>goog.vec.mat3f.rotateX = function(mat, angle) {
<a name="line876"></a>  var m01 = mat[3], m11 = mat[4], m21 = mat[5];
<a name="line877"></a>  var m02 = mat[6], m12 = mat[7], m22 = mat[8];
<a name="line878"></a>
<a name="line879"></a>  var c = Math.cos(angle);
<a name="line880"></a>  var s = Math.sin(angle);
<a name="line881"></a>
<a name="line882"></a>  mat[3] = m01 * c + m02 * s;
<a name="line883"></a>  mat[4] = m11 * c + m12 * s;
<a name="line884"></a>  mat[5] = m21 * c + m22 * s;
<a name="line885"></a>  mat[6] = m01 * -s + m02 * c;
<a name="line886"></a>  mat[7] = m11 * -s + m12 * c;
<a name="line887"></a>  mat[8] = m21 * -s + m22 * c;
<a name="line888"></a>
<a name="line889"></a>  return mat;
<a name="line890"></a>};
<a name="line891"></a>
<a name="line892"></a>
<a name="line893"></a>/**
<a name="line894"></a> * Rotate the given matrix by angle about the y axis.  Equivalent to:
<a name="line895"></a> * goog.vec.mat3f.multMat(
<a name="line896"></a> *     mat,
<a name="line897"></a> *     goog.vec.mat3f.makeRotateY(goog.vec.mat3f.create(), angle),
<a name="line898"></a> *     mat);
<a name="line899"></a> *
<a name="line900"></a> * @param {goog.vec.mat3f.Type} mat The matrix.
<a name="line901"></a> * @param {number} angle The angle in radians.
<a name="line902"></a> * @return {!goog.vec.mat3f.Type} return mat so that operations can be
<a name="line903"></a> *     chained.
<a name="line904"></a> */
<a name="line905"></a>goog.vec.mat3f.rotateY = function(mat, angle) {
<a name="line906"></a>  var m00 = mat[0], m10 = mat[1], m20 = mat[2];
<a name="line907"></a>  var m02 = mat[6], m12 = mat[7], m22 = mat[8];
<a name="line908"></a>
<a name="line909"></a>  var c = Math.cos(angle);
<a name="line910"></a>  var s = Math.sin(angle);
<a name="line911"></a>
<a name="line912"></a>  mat[0] = m00 * c + m02 * -s;
<a name="line913"></a>  mat[1] = m10 * c + m12 * -s;
<a name="line914"></a>  mat[2] = m20 * c + m22 * -s;
<a name="line915"></a>  mat[6] = m00 * s + m02 * c;
<a name="line916"></a>  mat[7] = m10 * s + m12 * c;
<a name="line917"></a>  mat[8] = m20 * s + m22 * c;
<a name="line918"></a>
<a name="line919"></a>  return mat;
<a name="line920"></a>};
<a name="line921"></a>
<a name="line922"></a>
<a name="line923"></a>/**
<a name="line924"></a> * Rotate the given matrix by angle about the z axis.  Equivalent to:
<a name="line925"></a> * goog.vec.mat3f.multMat(
<a name="line926"></a> *     mat,
<a name="line927"></a> *     goog.vec.mat3f.makeRotateZ(goog.vec.mat3f.create(), angle),
<a name="line928"></a> *     mat);
<a name="line929"></a> *
<a name="line930"></a> * @param {goog.vec.mat3f.Type} mat The matrix.
<a name="line931"></a> * @param {number} angle The angle in radians.
<a name="line932"></a> * @return {!goog.vec.mat3f.Type} return mat so that operations can be
<a name="line933"></a> *     chained.
<a name="line934"></a> */
<a name="line935"></a>goog.vec.mat3f.rotateZ = function(mat, angle) {
<a name="line936"></a>  var m00 = mat[0], m10 = mat[1], m20 = mat[2];
<a name="line937"></a>  var m01 = mat[3], m11 = mat[4], m21 = mat[5];
<a name="line938"></a>
<a name="line939"></a>  var c = Math.cos(angle);
<a name="line940"></a>  var s = Math.sin(angle);
<a name="line941"></a>
<a name="line942"></a>  mat[0] = m00 * c + m01 * s;
<a name="line943"></a>  mat[1] = m10 * c + m11 * s;
<a name="line944"></a>  mat[2] = m20 * c + m21 * s;
<a name="line945"></a>  mat[3] = m00 * -s + m01 * c;
<a name="line946"></a>  mat[4] = m10 * -s + m11 * c;
<a name="line947"></a>  mat[5] = m20 * -s + m21 * c;
<a name="line948"></a>
<a name="line949"></a>  return mat;
<a name="line950"></a>};
<a name="line951"></a>
<a name="line952"></a>
<a name="line953"></a>/**
<a name="line954"></a> * Makes the given 3x3 matrix a rotation matrix given Euler angles using
<a name="line955"></a> * the ZXZ convention.
<a name="line956"></a> * Given the euler angles [theta1, theta2, theta3], the rotation is defined as
<a name="line957"></a> * rotation = rotation_z(theta1) * rotation_x(theta2) * rotation_z(theta3),
<a name="line958"></a> * with theta1 in [0, 2 * pi], theta2 in [0, pi] and theta3 in [0, 2 * pi].
<a name="line959"></a> * rotation_x(theta) means rotation around the X axis of theta radians.
<a name="line960"></a> *
<a name="line961"></a> * @param {goog.vec.mat3f.Type} mat The matrix.
<a name="line962"></a> * @param {number} theta1 The angle of rotation around the Z axis in radians.
<a name="line963"></a> * @param {number} theta2 The angle of rotation around the X axis in radians.
<a name="line964"></a> * @param {number} theta3 The angle of rotation around the Z axis in radians.
<a name="line965"></a> * @return {!goog.vec.mat3f.Type} return mat so that operations can be
<a name="line966"></a> *     chained.
<a name="line967"></a> */
<a name="line968"></a>goog.vec.mat3f.makeEulerZXZ = function(mat, theta1, theta2, theta3) {
<a name="line969"></a>  var c1 = Math.cos(theta1);
<a name="line970"></a>  var s1 = Math.sin(theta1);
<a name="line971"></a>
<a name="line972"></a>  var c2 = Math.cos(theta2);
<a name="line973"></a>  var s2 = Math.sin(theta2);
<a name="line974"></a>
<a name="line975"></a>  var c3 = Math.cos(theta3);
<a name="line976"></a>  var s3 = Math.sin(theta3);
<a name="line977"></a>
<a name="line978"></a>  mat[0] = c1 * c3 - c2 * s1 * s3;
<a name="line979"></a>  mat[1] = c2 * c1 * s3 + c3 * s1;
<a name="line980"></a>  mat[2] = s3 * s2;
<a name="line981"></a>
<a name="line982"></a>  mat[3] = -c1 * s3 - c3 * c2 * s1;
<a name="line983"></a>  mat[4] = c1 * c2 * c3 - s1 * s3;
<a name="line984"></a>  mat[5] = c3 * s2;
<a name="line985"></a>
<a name="line986"></a>  mat[6] = s2 * s1;
<a name="line987"></a>  mat[7] = -c1 * s2;
<a name="line988"></a>  mat[8] = c2;
<a name="line989"></a>
<a name="line990"></a>  return mat;
<a name="line991"></a>};
<a name="line992"></a>
<a name="line993"></a>
<a name="line994"></a>/**
<a name="line995"></a> * Decomposes a rotation matrix into Euler angles using the ZXZ convention so
<a name="line996"></a> * that rotation = rotation_z(theta1) * rotation_x(theta2) * rotation_z(theta3),
<a name="line997"></a> * with theta1 in [0, 2 * pi], theta2 in [0, pi] and theta3 in [0, 2 * pi].
<a name="line998"></a> * rotation_x(theta) means rotation around the X axis of theta radians.
<a name="line999"></a> *
<a name="line1000"></a> * @param {goog.vec.mat3f.Type} mat The matrix.
<a name="line1001"></a> * @param {goog.vec.vec3f.Type} euler The ZXZ Euler angles in
<a name="line1002"></a> *     radians as [theta1, theta2, theta3].
<a name="line1003"></a> * @param {boolean=} opt_theta2IsNegative Whether theta2 is in [-pi, 0] instead
<a name="line1004"></a> *     of the default [0, pi].
<a name="line1005"></a> * @return {!goog.vec.vec3f.Type} return euler so that operations can be
<a name="line1006"></a> *     chained together.
<a name="line1007"></a> */
<a name="line1008"></a>goog.vec.mat3f.toEulerZXZ = function(mat, euler, opt_theta2IsNegative) {
<a name="line1009"></a>  // There is an ambiguity in the sign of sinTheta2 because of the sqrt.
<a name="line1010"></a>  var sinTheta2 = Math.sqrt(mat[2] * mat[2] + mat[5] * mat[5]);
<a name="line1011"></a>
<a name="line1012"></a>  // By default we explicitely constrain theta2 to be in [0, pi],
<a name="line1013"></a>  // so sinTheta2 is always positive. We can change the behavior and specify
<a name="line1014"></a>  // theta2 to be negative in [-pi, 0] with opt_Theta2IsNegative.
<a name="line1015"></a>  var signTheta2 = opt_theta2IsNegative ? -1 : 1;
<a name="line1016"></a>
<a name="line1017"></a>  if (sinTheta2 &gt; goog.vec.EPSILON) {
<a name="line1018"></a>    euler[2] = Math.atan2(mat[2] * signTheta2, mat[5] * signTheta2);
<a name="line1019"></a>    euler[1] = Math.atan2(sinTheta2 * signTheta2, mat[8]);
<a name="line1020"></a>    euler[0] = Math.atan2(mat[6] * signTheta2, -mat[7] * signTheta2);
<a name="line1021"></a>  } else {
<a name="line1022"></a>    // There is also an arbitrary choice for theta1 = 0 or theta2 = 0 here.
<a name="line1023"></a>    // We assume theta1 = 0 as some applications do not allow the camera to roll
<a name="line1024"></a>    // (i.e. have theta1 != 0).
<a name="line1025"></a>    euler[0] = 0;
<a name="line1026"></a>    euler[1] = Math.atan2(sinTheta2 * signTheta2, mat[8]);
<a name="line1027"></a>    euler[2] = Math.atan2(mat[1], mat[0]);
<a name="line1028"></a>  }
<a name="line1029"></a>
<a name="line1030"></a>  // Atan2 outputs angles in [-pi, pi] so we bring them back to [0, 2 * pi].
<a name="line1031"></a>  euler[0] = (euler[0] + Math.PI * 2) % (Math.PI * 2);
<a name="line1032"></a>  euler[2] = (euler[2] + Math.PI * 2) % (Math.PI * 2);
<a name="line1033"></a>  // For theta2 we want the angle to be in [0, pi] or [-pi, 0] depending on
<a name="line1034"></a>  // signTheta2.
<a name="line1035"></a>  euler[1] = ((euler[1] * signTheta2 + Math.PI * 2) % (Math.PI * 2)) *
<a name="line1036"></a>      signTheta2;
<a name="line1037"></a>
<a name="line1038"></a>  return euler;
<a name="line1039"></a>};
</pre>


</body>
</html>
